<?php

namespace app\common\utils;

use app\common\service\JsonService;
use Firebase\JWT\JWT;
use Firebase\JWT\Key;
use think\facade\Env;

class JWTUtils
{
    public static function generateToken(int $adminId): string
    {
        return JWT::encode([
            'uid'=>$adminId,
        ],  Env::get('project.jwt_key'), 'HS256');
    }

    public static function getPayLoad(string $token)
    {
        try {
            return JWT::decode($token,new Key(Env::get('project.jwt_key'), 'HS256'));
        }catch (\Exception $e){
            return JsonService::errorWithMsg($e->getMessage());
        }
    }
}